package com.baselib.android.event;


import org.greenrobot.eventbus.EventBus;

/****
 * 时间总线管理器
 * @author HW
 *
 */
public class EventManager {

    private static EventManager manager;
    private EventBus eventBus;

    private EventManager() {
        eventBus = EventBus.getDefault();
    }

    public static EventManager getInstance() {
        if (null == manager) {
            manager = new EventManager();
        }
        return manager;
    }


    public void register(Object subscriber) {
        if (isRegister(subscriber))
            return;
        EventBus.getDefault().register(subscriber);//订阅
    }

    public void register(Object subscriber, int priority) {
		if(isRegister(subscriber))
			return;
		this.eventBus.register(subscriber);
    }


    public void unregister(Object subscriber) {
        EventBus.getDefault().unregister(subscriber);//解除订阅
    }


    public void post(Object event) {
        EventBus.getDefault().post(event);
    }

    public void postSticky(Object event) {
        this.eventBus.postSticky(event);
    }

    public boolean isRegister(Object subscriber) {
        return EventBus.getDefault().isRegistered(subscriber);
    }


}
